namespace EyeOpen.Security.Service
{
	using System.Linq;

	using EyeOpen.Security.Data;

	public class UserLoginService
	{
		public bool IsValidUser(string email, string password, ISecurityUnitOfWork uow)
		{
			var user = 
				uow
					.UserRepository
					.SingleOrDefault(u => u.Email == email);

			if (user == null)
			{
				return false;
			}
			
			var passwordByte = Domain.User.CreatePassword(password);

			return user.Password.SequenceEqual(passwordByte);
		}
	}
}